*********motivation -- state college grad retention rates and measures of mobility

****make cz-level data on income mobility and covariates
use "$data/LOO/onlinedata5", clear
keep cz e_rank_b_8082
ren e iim

//merge on covariates
merge 1:1 cz using "$data/LOO/onlinedata8"
ren state state
merge m:1 state using "$data/Crosswalks/state_fips_crosswalk", keep(match) nogen

//limit variables
ren state stateabbrv
keep cz iim cs_fam_wkids cs_race_bla cs_race_theil cs_labforce gini ccd_pup_tch_ratio stateabbrv pop2000 *mig*

//merge on CZ outflow rates
preserve
use cz coll_pooled_pooled_mean hs_pooled_pooled_mean jail_pooled_pooled_mean married_pooled_pooled_mean staycz_pooled_pooled_p25 using "$data/Opp_Atlas/cz_outcomes", clear
tempfile stay
save `stay'
restore

merge 1:1 cz using `stay', keep(match) nogen

//renaming
replace stay = 1-stay
ren stay native_outflow
ren jail crime
ren hs_pooled hs_gradrate
ren coll_pooled coll_gradrate
ren married married 

//maps
maptile iim, geo(cz1990) stateoutline(medium) n(7) rev spopt(mos(thick)) legdecimals(1) ///
savegraph("$output/fig2_cz_mobility.png") replace
graph close

replace native_outflow = native_outflow*100
maptile native_outflow, geo(cz1990) stateoutline(medium) n(7) rev spopt(mos(thick)) legdecimals(1) ///
savegraph("$output/fig2_cz_outflow.png") replace
graph close

//rescale variables for consistency with percentiles
ds cs_race_bla cs_fam_wkids cs_race_theil cs_labforce ///
gini married coll_gradrate hs_gradrate crime

foreach var in `r(varlist)'{
	replace `var' = `var'*100
}

//variable labelling
lab var native_outflow "Native Outflow" 
lab var ccd_pup_tch_ratio "Student-Teacher Ratio"
lab var cs_labforce "LFP Rate"
lab var cs_race_bla "Share Black"
lab var cs_fam_wkids "Share Single Mothers"
lab var cs_race_theil "Theil Segregation Index"
lab var coll_gradrate "College Graduation Rate"
lab var hs_gradrate "HS Dropout Rate"	
lab var crime "Share Incarcerated"
lab var gini "Gini Coefficient"
lab var married "Share Married" 
 
//now some regressions!
reg iim cs_fam_wkids cs_race_bla cs_race_theil coll_gradrate hs_gradrate crime gini married, robust
outreg2 using "$output/Regressions/cz_motivation_v2", replace noast tex lab

reg iim cs_labforce cs_fam_wkids cs_race_bla cs_race_theil coll_gradrate hs_gradrate crime gini married, robust
outreg2 using "$output/Regressions/cz_motivation_v2", noast tex lab

reg iim ccd_pup_tch_ratio cs_labforce  cs_fam_wkids cs_race_bla cs_race_theil coll_gradrate hs_gradrate crime gini married, robust
outreg2 using "$output/Regressions/cz_motivation_v2", noast tex lab

reg iim native_outflow ccd_pup_tch_ratio cs_labforce  cs_fam_wkids cs_race_bla cs_race_theil coll_gradrate hs_gradrate crime gini married, robust
outreg2 using "$output/Regressions/cz_motivation_v2", noast tex lab

//end of do-file